package org.boun.swe.ARCEONE.Adapter;

import java.util.List;

import org.boun.swe.ARCEONE.R;
import org.boun.swe.ARCEONE.Data.Tag;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class TagAdapter extends BaseAdapter{
	private List<Tag> tagList;
	private Context context;
	private SimpleListCell cell;
	
	public TagAdapter(List<Tag> list, Context context) {
		tagList = list;
		this.context = context;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
	    View rowView = convertView;  
	    Tag tag = tagList.get(position);
	    
		if(rowView == null){
			cell = new SimpleListCell();
			LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        rowView = layoutInflater.inflate(R.layout.tag_list_item, null);
	        cell.cellTitle = (TextView)rowView.findViewById(R.id.tagTitle);
	        cell.cellSelected = (CheckBox)rowView.findViewById(R.id.isTagSelected);
	        rowView.setTag(cell);
		}
		else
			cell = (SimpleListCell)rowView.getTag();

        cell.cellTitle.setText(tag.toString());
        cell.cellSelected.setChecked(tag.isSelected);
	    return rowView;
	}
	
	@Override
	public int getCount() {
		return tagList.size();
	}

	@Override
	public Object getItem(int position) {
		return tagList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	public void ToggleCheckBox(int position){
		tagList.get(position);
	}
}
